<!--
 * @Description: 页面模板
 * @Version: 1.0
 * @Autor: tao
 * @Date: 2021-01-15 16:19:27
 * @LastEditors: tao
 * @LastEditTime: 2021-01-21 11:53:59
-->

<template>
  <div class="Inventory">
    <Management>
      <Top
        slot="top"
        @showModel="showModel"
        @showAll="showAll"
        @search="onSearch"
      ></Top>
      <Table
        slot="body"
        :title="columns"
        :tableData="tableData"
        @edit="edit"
        @del="del"
        @changePage="changePage"
      ></Table>
    </Management>
    <Dialog :show="isShow" @confirm="confirm" @cancel="cancel">
      <div slot="form">sd</div>
    </Dialog>
  </div>
</template>

<script>
import Table from "components/common/table/Table";
import Management from "components/common/management/Management";
import Top from "./component/Top";
import Dialog from "./component/Dialog";
import {
  getDataByPageAndSize,
  appendData,
  deleteById,
  editData,
  searchById,
} from "network/t-project";

export default {
  components: {
    Table,
    Top,
    Management,
    Dialog,
  },
  data() {
    const columns = [
      {
        title: "id",
        dataIndex: "id",
      },
      {
        title: "名称",
        dataIndex: "name",
      },
      {
        title: "编号",
        dataIndex: "number",
      },
      {
        title: "负责人",
        dataIndex: "leader",
      },
      {
        title: "成员",
        dataIndex: "member",
      },
      {
        title: "类型",
        dataIndex: "type",
      },
      {
        title: "级别",
        dataIndex: "level",
      },
      {
        title: "申报",
        dataIndex: "status",
      },
      {
        title: "申报书",
        dataIndex: "file",
      },
      {
        title: "审核",
        dataIndex: "check",
      },
    ];
    return {
      tableData: [],
      columns,
      isShow: false,
    };
  },
  created() {
    this.init();
  },
  methods: {
    /**
     * @description: 初始化页面
     * @param {Number} page
     * @param {Number} size
     * @author: tao
     */
    async init(page = 1, size = 10) {
      const result = await getDataByPageAndSize(page, size);
      console.log(result);
    },

    del(e) {
      console.log(e);
    },

    /**
     * @description: 点击弹窗 确定 按钮
     * @param {Object} data
     * @author: tao
     */
    async confirm(data) {
      console.log(data);
      this.closeDialog();
      return;
      if (data.edit) {
        // 编辑数据
        const result = await editData();
        console.log(result);
      } else {
        //增加数据
        const result = await appendData();
        console.log(result);
      }
    },

    changePage(page) {
      this.init(page);
    },

    onSearch(value) {
      console.log(value);
    },

    showAll() {
      this.init();
    },

    showModel() {
      this.isShow = true;
    },

    edit() {
      this.isShow = true;
    },

    cancel() {
      this.closeDialog();
    },

    closeDialog() {
      this.isShow = false;
    },
  },
};
</script>

<style lang="less" scoped>
.Inventory {
  height: 100%;
  display: flex;
  flex-direction: column;
  .InventoryTable {
    flex: 1;
  }
}
</style>
